package cn.neusoft.neusoft_fz.service.impl;


import cn.neusoft.neusoft_fz.entity.PaymentEntity;
import cn.neusoft.neusoft_fz.mapper.PaymentMapper;
import cn.neusoft.neusoft_fz.service.PaymentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.entity.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2023-06-25
 */
@Service
public class PaymentServiceImpl extends ServiceImpl<PaymentMapper, Payment> implements PaymentService {
    @Autowired
    private PaymentMapper paymentMapper;

    public List<Payment> getPaymentsBySubstationAndTime(Long substationId, LocalDateTime startTime, LocalDateTime endTime) {
        Map<String, Object> params = new HashMap<>();
        params.put("substationId", substationId);
        params.put("startTime", startTime);
        params.put("endTime", endTime);

        return paymentMapper.findPaymentsBySubstationAndTime(params);
    }

    @Override
    public List<Payment> getPaymentsBySubstation(Long substationId) {
        Map<String, Object> params = new HashMap<>();
        params.put("substationId", substationId);
        return paymentMapper.findPaymentsBySubstation(params);
    }

    @Override
    public BigDecimal getPaymentAmount(String doid) {
        PaymentEntity paymentAmount = paymentMapper.getPaymentAmount(doid);
        return paymentAmount.calculateAmount();
    }
}
